<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=30f1373e8cea1b4b0e5c77fc7065480c"></script>
<script type="text/javascript" src="/static/jquip/jquip.all.min.js"></script>
<title>百度地图的Hello, World</title>
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}
</style>
</head>
<body>
经度：<span id="longitude"></span>   纬度:<span id="latitude"></span> <br/>
地址:<input id="address" type="text"></input><br/>
<input type="text" id="t_name"></input><input id="b_search" type="button" value="搜索"></input>

<div id="allmap"></div>

</body>
</html>
<script type="text/javascript">
//var posResult
// 百度地图API功能
var map = new BMap.Map("allmap");            // 创建Map实例
var point = new BMap.Point({{longitude}}, {{latitude}});    // 创建点坐标
map.centerAndZoom(point,15);                     // 初始化地图,设置中心点坐标和地图级别。
map.enableScrollWheelZoom();                            //启用滚轮放大缩小
// 创建地理编码实例  
var myGeo = new BMap.Geocoder(); 
map.addEventListener("click", function(e){

//var walking = new BMap.WalkingRoute(map, {renderOptions:{map: map, autoViewport: true}});
//walking.search("海讯电子", "春熙路");


  $("#longitude").text(e.point.lng);
  $("#latitude").text(e.point.lat);
  // 根据坐标得到地址描述  
  myGeo.getLocation(new BMap.Point(e.point.lng, e.point.lat), function(result){    
   if (result){
      parent.posResult=result
      $("#address").val(result.address);
      //alert(result.addressComponents.city);
   }    
  });   

})

$("#b_search").click(function(){
    var name=$("#t_name").val();
    if (name==""){
        alert("请输入关键字！");
        return;
    }
        
    var local = new BMap.LocalSearch(map, {    
      renderOptions:{map: map}    
    });    
    local.search(name);  
});

function test()
{

//折线,就是多点的直线
var polyline = new BMap.Polyline([
   new BMap.Point(104.063108, 30.670757),
   new BMap.Point(104.058724, 30.653982)
 ],
 {strokeColor:"blue", strokeWeight:6, strokeOpacity:0.5}
);
map.addOverlay(polyline);


//标注
var marker = new BMap.Marker(e.point);        // 创建标注
map.addOverlay(marker);                     // 将标注添加到地图中


//点击标注
marker.addEventListener("click", function(){
 alert("您点击了标注");
});


//弹出信息窗
var opts = {
 width : 250,     // 信息窗口宽度
 height: 100,     // 信息窗口高度
 title : "Hello"  // 信息窗口标题
}
var infoWindow = new BMap.InfoWindow("World", opts);  // 创建信息窗口对象
map.openInfoWindow(infoWindow, e.point);      // 打开信息窗口
}
   


</script>
